@extends('base')
@section('title', '$title')
@section('csses')
@endsection
@section('content')
    <div class="col-md-12" style="margin-bottom: 20px;">
    

        <ul class="nav nav-tabs">
          <li role="presentation" class="{{ ($type == 'table') ? 'active' : '' }}"><a href="{{ action('VolumeController@list', ['$type'=>'table']) }}">Table View</a></li>
          <li role="presentation" class="{{ ($type == 'years') ? 'active' : '' }}"><a href="{{ action('VolumeController@list') }}" >Years List</a></li>
          <li role="presentation" class="{{ ($type == 'list') ? 'active' : '' }}"><a href="{{ action('VolumeController@list', ['$type'=>'list']) }}" >List View</a></li>
        </ul>
    </div>

    <div class="col-md-12">
        @foreach($issues as $issue)
        <div class="col-xs-12 col-sm-4 col-md-2" style="text-align: center; margin-bottom: 10px;">
            
            <a href="{{ ($issue->isIncoming()) ? 'javascript:void(0);' : route('issue.index', ['issue' => $issue->id]) }}" style="position: relative;display: block;">
                @if ($issue->isIncoming())
                <span class="label label-warning" style="position: absolute;">Coming Soon</span>
                @endif
                <img width="104" height="150" style="border:1px solid #ccc;" src="{{ asset('uploads/' . $issue->cover) }}">
            </a>
            <span style="display: block; margin-top: 10px;">{{ $issue->year }}&nbsp;Vol.{{ $issue->volume }}&nbsp;No.{{ $issue->issue }}</span>
        </div>
        @endforeach
    </div>

    <div class="col-md-12" style="padding-left: 45px" >
        <hr style="height:1px;border:none;border-top:1px solid #ddd;" />
    </div>



    @if( $type == 'years')
    <div class="col-md-12" style="padding-left: 45px">
        @for($i=floor(date('Y')/10) * 10; $i >= 1980 ; $i-=10)
        <div>
            <span class="label label-primary" style="line-height: 2; font-size: 100%">{{$i}}s</span>
            
            @for($j=0; $j<10; $j++)
                @if(($i + $j) <= date('Y') )
                    <a class="label label-info" style="line-height: 2; font-size: 100%" href="{{ route('volume.index', ['volume' => $i + $j]) }}"> {{ $i + $j }}</a>
                @endif
            @endfor
        </div>
        @endfor
    </div>
    @endif

    @if( $type == 'table')
    <div class="col-md-12" style="padding-left: 45px">

      <table class="table table-bordered">
        <tbody>
          @for($i=date('Y'); $i >= 1980; $i--)
              <tr>
                <th scope="row">{{$i}}<br>Vol. {{ $i - 1980 + 1 }}</th>

                 <?php $issues = App\Models\Issue::where('year', $i)->orderBy('journal_published', 'desc')->get(); ?>
                @foreach ($issues as $issue)
                  <td><a href="{{ route('issue.index', ['issue'=> $issue->id])}}">
                    No.{{ $issue->issue }}<br>
                    {{$issue->journal_published}}<br>
                    pp.{{ $issue->page_start }}-{{ $issue->page_end }}
                  </a></td>
                @endforeach
              </tr>
          @endfor
        </tbody>
      </table>
    </div>
    @endif

    @if( $type == 'list')
    <div class="col-md-12" style="padding-left: 45px">
      @for($i=date('Y'); $i >= 1980; $i--)
      <dl>
        <dt><b>{{$i}}</b></dt>
        <?php $issues = App\Models\Issue::where('year', $i)->orderBy('journal_published', 'desc')->get(); ?>
        @foreach ($issues as $issue)
          <dd>
            <a href="{{ route('issue.index', ['issue'=> $issue->id])}}">
              {{ $issue->getTitle() }}
            </a>
          </dd>
        @endforeach
        
      </dl>
      @endfor
    </div>
    @endif
@endsection